package com.lkyh.mes.codegen.util;

import cn.hutool.core.util.ReUtil;
import lombok.experimental.UtilityClass;
import lombok.extern.slf4j.Slf4j;
import ognl.OgnlContext;

import java.util.List;
import java.util.regex.Pattern;

@Slf4j
@UtilityClass
public class FormUtils {

	public Object getVal(String val, OgnlContext context) {
		try {
			return ognl.Ognl.getValue(val, context, context.getRoot());
		} catch (Exception e) {
			log.error(String.format("转换Ognl表达式异常,表达式:%s,上下文:%s}", val, context), e);
		}
		return null;
	}


	public static void main(String[] args) {
//		Pattern compile = Pattern.compile("@\\w+\\(.[^\\)]*\\)");
		Pattern compile = Pattern.compile("@(.*?)\\((.*?)\\)");

		List<String> allGroups = ReUtil.findAll(compile, "@aaa(@vvv()) && @aaa(#data.name)", 0);
		System.out.println(allGroups.toString());
	}
}
